﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using DAL.EntityDataModel;

namespace BLL.Formateur
{
    public class FormateurBLL
    {
        /// <summary>
        /// Return all formations
        /// </summary>
        /// <returns></returns>
        public static List<FormateurBO> GetFomateurs()
        {
            List<FormateurBO> formateursBO = new List<FormateurBO>();
            List<DAL.EntityDataModel.Formateur> formateurs = new List<DAL.EntityDataModel.Formateur>();

            using (DBEntities db = new DBEntities())
            {

                try
                {
                    formateurs = db.Formateurs.ToList();

                    formateursBO = FormateurBLL.CopyeEntitiesToBOlist(formateurs);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

            }

            return formateursBO;
        }
        
        /*****************************
         * Public traitement Method
         *****************************/

        /// <summary>
        /// Copy a entity to a business object
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static FormateurBO CopyEntityToBO(DAL.EntityDataModel.Formateur entity)
        {
            FormateurBO bo = new FormateurBO();

            try
            {
                bo.Email = entity.Email;
                bo.IdCivilite = entity.Civilite.Identifiant;
                bo.Identifiant = entity.Identifiant;
                bo.Infos = entity.Infos;
                bo.IntervenantExterieur = entity.IntervernantExterieur;
                bo.Nom = entity.Nom;
                bo.NomFichierPhoto = entity.NomFichierPhoto;
                bo.Prenom = entity.Prenom;
                bo.Telephone = entity.Telephone;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return bo;
        }

        /// <summary>
        /// Copy Business to entity
        /// </summary>
        /// <param name="bo"></param>
        /// <returns></returns>
        public static void CopyBoToEntity(FormateurBO bo, DAL.EntityDataModel.Formateur entity)
        {
            try
            {
                if (bo.Identifiant != 0)
                    entity.Identifiant = bo.Identifiant;

                entity.Email = bo.Email;
                entity.Civilite.Identifiant = entity.IdCivilite;
                entity.Identifiant = bo.Identifiant;
                entity.Infos = bo.Infos;
                entity.IntervernantExterieur = bo.IntervenantExterieur;
                entity.Nom = bo.Nom;
                entity.NomFichierPhoto = bo.NomFichierPhoto;
                entity.Prenom = bo.Prenom;
                entity.Telephone = bo.Telephone;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// Copy entities to a list of business object
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static List<FormateurBO> CopyeEntitiesToBOlist(List<DAL.EntityDataModel.Formateur> entities)
        {
            List<FormateurBO> boList = new List<FormateurBO>();

            try
            {
                foreach (DAL.EntityDataModel.Formateur entity in entities)
                {
                    FormateurBO bo = FormateurBLL.CopyEntityToBO(entity);
                    boList.Add(bo);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return boList;
        }
    }
}
